package com.cdainfo.vaadin;

import org.apache.commons.lang.StringUtils;

import com.cdainfo.vaadin.listener.DateFieldChangedListener;
import com.vaadin.ui.PopupDateField;

public class PopupDateFieldFormat extends PopupDateField {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4487245160898460521L;
	
	private static final String FORMATO_POR_DEFECTO = "dd/MM/yyyy HH:mm";
	
	private static final String METHOD_DATE_FIELD_CHANGED = "dateFieldValueChange";

	public PopupDateFieldFormat() {
		this(null);
	}
	
	public PopupDateFieldFormat(String formato)
	{
		if(StringUtils.isEmpty(formato))
		{
			formato = FORMATO_POR_DEFECTO;
		}
		
		setResolution(RESOLUTION_MIN);
		
		setDateFormat(formato);
	}
	
	public void addListener(DateFieldChangedListener listener) {
		super.addListener(ValueChangeEvent.class, listener, METHOD_DATE_FIELD_CHANGED);
	}
	
	public void removeListener(DateFieldChangedListener listener) {
		super.removeListener(ValueChangeEvent.class, listener, METHOD_DATE_FIELD_CHANGED);
	}
	
	/*@Override
	public void changeVariables(Object source, Map<String, Object> variables) {
		super.changeVariables(source, variables);
		if (variables.containsKey(METHOD_DATE_FIELD_CHANGED)) {
			fireDateFieldChanged();
		}
	}

	private void fireDateFieldChanged() {
		fireEvent(new DateFieldChangedEvent(this));
	}*/
	
}
